package cn.liuyi.weiyi;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import cn.edu.pku.tools.SharedPreferencesHelper;
import cn.edu.pku.tools.YJRHttpClient;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.PersistentCookieStore;
import com.loopj.android.http.RequestParams;

public class AddDesActivity extends SherlockActivity{

	LayoutInflater inflater;
	ActionBar actionBar;
	EditText name_edit_et;
	View title_bar;
	Context context;
	String response;
	JSONObject jsonInfo;
	static final int LOGIN_MSG = 0;
	TextView save_tv;
	SharedPreferencesHelper spHelper;
	String age;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_des);
		inflater = this.getLayoutInflater();
		actionBar = getSupportActionBar();
		context = this;
		this.spHelper = new SharedPreferencesHelper(this.context);
		initTitleBar();
		
		initComponent();
		
		initEventListener();
		
		
		
	
	}
	
	private void initTitleBar(){
		ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,ActionBar.LayoutParams.WRAP_CONTENT,Gravity.CENTER);
	    this.title_bar = this.inflater.inflate(R.layout.add_des_action_bar, null);
	    this.actionBar.setCustomView(this.title_bar, lp);
	    this.actionBar.setDisplayShowHomeEnabled(false);
	    this.actionBar.setDisplayShowTitleEnabled(false);
	    this.actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
	    this.actionBar.setDisplayShowCustomEnabled(true);
	}
	private void initComponent(){
		name_edit_et = (EditText) findViewById(R.id.name_edit_et);
		save_tv = (TextView) title_bar.findViewById(R.id.save);
	}
	
	
	private void initEventListener(){
		save_tv.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				age = name_edit_et.getText().toString();
				if(age == null||age.equals("")){
					Toast.makeText(context, "描述信息不能为空，请输入后再保存", Toast.LENGTH_SHORT).show();
				}else{
					saveName(age);
				}
			}
			
		});
	}
	
	private void saveName(String name_){
	
			Intent intent = new Intent();
			intent.putExtra("des", name_);
			((Activity) context).setResult(Activity.RESULT_OK,intent);
			((Activity) context).finish();
	}
	
	

}